/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;

/**
 *
 * @author NoiR
 */
public class DBConnection {

    public static Connection getConnection() {
        Connection c = null;
        try {
            Properties props = new Properties();

            props.load(new FileInputStream("src/java/config.properties"));

            String driver = props.getProperty("driver");
            String url = props.getProperty("url");

            Class.forName(driver);
            c = DriverManager.getConnection(url);
            // c = DriverManager.getConnection(url,"tiwtiger_SQLLogin_1","12345678"); // TanND
        } catch (IOException ex) {
            Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
        }

        return c;
    }

    public static Connection getConnection(ServletContext context) {
        Connection c = null;
        try {
            Properties props = new Properties();

            props.load(new FileInputStream("src/java/config.properties"));

            String driver = props.getProperty("driver");
            String url = props.getProperty("url");

            Class.forName(driver);
            c = DriverManager.getConnection(url);
        } catch (IOException ex) {
            Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
        }

        return c;
    }
}
